package com.cynen.job.task;

import com.cynen.job.pojo.JobInfo;
import com.cynen.job.service.JobInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 自定义的Pipline...
 */
@Component
public class JobPipline implements Pipeline {

    @Autowired
    private JobInfoService jobInfoService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        // 获取到保存到resultItems中的对象数据
        JobInfo jobinfo = resultItems.get("jobinfo");
        if (jobinfo != null){
            // 获取数据,存储到数据库.
            this.jobInfoService.save(jobinfo);
        }

    }
}
